package cn.com.api.controller;

import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.api.entity.ApiT_member_partner_task;

import cn.com.api.service.ApiT_member_partner_taskService;

import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_API + "t_member_partner_task/")
public class ApiT_member_partner_taskController {
    @Autowired
    private ApiT_member_partner_taskService apiT_member_partner_taskService;
	
	private static Logger logger = Logger.getLogger(ApiT_member_partner_taskController.class);
	
	/**
	 * 新增
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "insertT_member_partner_task")
	public void insertT_member_partner_task(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		String id = request.getParameter("id");
		String task_name = request.getParameter("task_name");
		String invite_partner_amount = request.getParameter("invite_partner_amount");
		String invite_entrepreneur_amount = request.getParameter("invite_entrepreneur_amount");
		String advert_money = request.getParameter("advert_money");
		String complete_time = request.getParameter("complete_time");
		String ext1 = request.getParameter("ext1");
		String ext2 = request.getParameter("ext2");
		String ext3 = request.getParameter("ext3");
		String ext4 = request.getParameter("ext4");
		String ext5 = request.getParameter("ext5");
		String award_money = request.getParameter("award_money");
        
		Map<String,Object> map = new HashMap<String,Object>();
		
		try{
			if(id!=null && !"".equals(id.trim())){
				ApiT_member_partner_task t_member_partner_task = new ApiT_member_partner_task();
				
    		    //t_member_partner_task.setId(id);
    		    //t_member_partner_task.setTask_name(task_name);
    		    //t_member_partner_task.setInvite_partner_amount(invite_partner_amount);
    		    //t_member_partner_task.setInvite_entrepreneur_amount(invite_entrepreneur_amount);
    		    //t_member_partner_task.setAdvert_money(advert_money);
    		    //t_member_partner_task.setComplete_time(complete_time);
    		    //t_member_partner_task.setExt1(ext1);
    		    //t_member_partner_task.setExt2(ext2);
    		    //t_member_partner_task.setExt3(ext3);
    		    //t_member_partner_task.setExt4(ext4);
    		    //t_member_partner_task.setExt5(ext5);
    		    //t_member_partner_task.setAward_money(award_money);
				
				apiT_member_partner_taskService.insertT_member_partner_task(t_member_partner_task);
				// return
                map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "添加成功！");
			}
		}catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
    		map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
    		map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 根据id查询
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/findT_member_partner_taskById")
	public void findT_member_partner_taskById(HttpServletRequest request, HttpServletResponse response) throws Exception {
	
		Map<String,Object> map = new HashMap<String,Object>();
		try{
		    String id = request.getParameter("id");
		    ApiT_member_partner_task t_member_partner_task = apiT_member_partner_taskService.findT_member_partner_taskById(Integer.valueOf(id));
		
			// return
            map.put("datas", t_member_partner_task);
            map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "查询成功！");
		}catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
    		map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
    		map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
        
	}
	
     /**
	 * 查询数据集
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/findT_member_partner_tasks")
	public void findT_member_partner_tasks(HttpServletRequest request, HttpServletResponse response) throws Exception {
	
		Map<String,Object> map = new HashMap<String,Object>();
		try{
		    List<ApiT_member_partner_task> t_member_partner_tasks = apiT_member_partner_taskService.findT_member_partner_tasks();
		
			// return
            map.put("datas", t_member_partner_tasks);
            map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "查询成功！");
		}catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
    		map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
    		map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
        
	}
	
    
	/**
	 * 修改
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception 
	 */
	@Transactional
	@RequestMapping(value = "updateT_member_partner_task")
	public void updateT_member_partner_task(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		String id = request.getParameter("id");
		String task_name = request.getParameter("task_name");
		String invite_partner_amount = request.getParameter("invite_partner_amount");
		String invite_entrepreneur_amount = request.getParameter("invite_entrepreneur_amount");
		String advert_money = request.getParameter("advert_money");
		String complete_time = request.getParameter("complete_time");
		String ext1 = request.getParameter("ext1");
		String ext2 = request.getParameter("ext2");
		String ext3 = request.getParameter("ext3");
		String ext4 = request.getParameter("ext4");
		String ext5 = request.getParameter("ext5");
		String award_money = request.getParameter("award_money");
        
        
		//String id = request.getParameter("id");
		Map<String,Object> map = new HashMap<String,Object>();
		
		try{
			if(id!=null && !"".equals(id.trim())){
				ApiT_member_partner_task t_member_partner_task = new ApiT_member_partner_task();
				//获取原数据
				t_member_partner_task  = apiT_member_partner_taskService.findT_member_partner_taskById(Integer.valueOf(id));
				//修改
				//t_member_partner_task.setIs_open(Integer.valueOf(is_open));
				//
				int ret_i = apiT_member_partner_taskService.updateT_member_partner_task(t_member_partner_task);
				
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "编辑成功！");
			}else{
				map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				map.put(Utils.MESSAGE, "检查失败！");
			}
		}
		catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
    
	/**
	 * 删除
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "deleteT_member_partner_task")
	public void deleteT_member_partner_task(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
        String id = request.getParameter("id");
		Map<String,Object> map = new HashMap<String,Object>();
		
		try{
			if(id!=null && !"".equals(id.trim())){
	
				Integer ret_I = apiT_member_partner_taskService.deleteT_member_partner_task(Integer.parseInt(id));
				if(ret_I >0 ){
    				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
    				map.put(Utils.MESSAGE, "删除成功！");
                }else{
				    map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				    map.put(Utils.MESSAGE, "检查失败！");
			    }
			}
		}catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
    		map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
    		map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}
	
 
}


